#ifndef PUSHSERVER_GLOBAL_H
#define PUSHSERVER_GLOBAL_H

#include <string>
#include <logger/Logger.h>

using std::string;
using std::to_string;

set<int> signals{
        SIGTERM,
        SIGINT,
};

/**信号捕获器，捕获到退出相关信号时关闭 sql链接 等
 *
 */
void ActivateSignalsListen() {
    for (auto &_: signals) {
        signal(_, [](int signum) -> void {
            Logger *logger = new Logger("信号捕获器");
            string msg = "捕获信号:" + to_string(signum);
            SPDLOG_LOGGER_INFO(logger, msg);
            delete svr;
            SPDLOG_LOGGER_INFO(logger, "http服务器停止");
            delete sqlServer;
            SPDLOG_LOGGER_INFO(logger, "数据库链接断开");
            SPDLOG_LOGGER_INFO(logger, "程序退出");
            exit(EXIT_SUCCESS);
        });
    }
}

#endif //PUSHSERVER_GLOBAL_H
